<template>
  <transition name="slide">
    <MusicList :songs="songs" :title="title" :bg-image="bgImage"></MusicList>
  </transition>
</template>

<script type="text/ecmascript-6">
import { getSingerDetail, getSong } from '@/api/singer'
import { ERR_OK } from '@/api/config'
import { createSong } from '@/assets/js/song'
import { mapGetters } from 'vuex'
import MusicList from '../music-list/music-list'
export default {
  computed: {
    ...mapGetters(['singer']),
    title() {
      return this.singer.name
    },
    bgImage() {
      return this.singer.avatar
    }
  },
  data() {
    return {
      songs: []
    }
  },
  created() {
    // console.log(this.singer)
    this._getDetail()
  },
  mounted() {
    // 获取动态路由的传值
    // console.log(this.$route.params.id)
  },
  methods: {
    _getDetail() {
      if (!this.singer.id) {
        this.$router.push('/singer')
      }
      getSingerDetail(this.singer.id).then((res) => {
        if (res.code === ERR_OK) {
          // console.log(res)
          console.log(res.data.list)
          this.songs = this._normalizeSongs(res.data.list)
          console.log(this.songs)
        }
      })
    },
    _normalizeSongs(list) {
      let ret = []
      list.forEach((item) => {
        let { musicData } = item
        if (musicData.songid && musicData.albummid) {
          ret.push(createSong(musicData))
        }
      })
      return ret
    }
  },
  components: { MusicList }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
@import '~@/assets/stylus/variable';

.slide-enter-active, .slide-leave-active {
  transition: all 0.3s ease;
}

.slide-enter, .slide-leave-to {
  transform: translate3d(100%, 0, 0);
}
</style>